<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation
require_once("controlHeader.php");					//--> system control header
include_once("QA.php");								//--> qa
require_once("../tools/fckeditor/fckeditor.php") ;

$objOperate = new Operation($objSession->getLanguage());	//--> Operation
$objQA 		= new QA($objSession->getLanguage(), $uid);	//--> qa

$error_message 	= '';

$question	= '';
$answer		= '';
$status		= 'approved';

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(isset($_POST['Submit'])){
	$question	= $_POST['question'];
	$answer 	= $_POST['answer'];
	$status 	= $_POST['status'];
		
	if(empty($question))
		$error_message = 'question should\'t be empty.';
	else if(empty($answer))
		$error_message = 'answer should\'t be empty.';
	else{
		$isReturn = $objQA->add($arrOperate, '', $question, $answer, $status);
		if($isReturn)
			$error_message = 'add successfully.';
		else 
			$error_message = 'add failure.';
	}
}


/*----- load FCKEditor -----*/
$oFCKeditor = new FCKeditor('answer') ;

$oFCKeditor->Height		= $fckEditorHeight;
$oFCKeditor->BasePath	= $fckBasePath;

$oFCKeditor->Value = $answer;

$fckHtml = $oFCKeditor->CreateHtml() ;

$arrStatus	= array('approved' => 'approved', 'unapproved' => 'unapproved');

/*----- out html -----*/
$smarty = new Smarty();		//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('backurl',$backurl);
$smarty->assign('error_message', $error_message);

$smarty->assign('question', $question);
$smarty->assign('answer', $answer);

$smarty->assign('arrStatus', $arrStatus);
$smarty->assign('statusS', $status);

$smarty->assign("fckHtml", $fckHtml);

$smarty->display('listQA_Add.htm');
?>
